package com.wly.ui.gamescene
{
	import com.wly.ui.rope.RedRope;
	import com.wly.ui.rope.RedRopePeer;
	
	import flash.display.Sprite;
	import flash.geom.Point;

	public class RedLineDrawItem extends DrawItem
	{
		private var _mcRope:Sprite;
		private var _peerLeft:Sprite;
		private var _peerRight:Sprite;
		
		public function RedLineDrawItem()
		{
			super();
			mouseChildren = false;
			mouseEnabled  = false;
		}
		
		override public function drawTo(endPos:Point):void
		{
			//graphics.clear();
			
			if(!startPos)
			{
				return;
			}
			
			if(!_mcRope)
			{
				_mcRope = new RedRope();
				addChild(_mcRope);
			}
			
			if(!_peerLeft)
			{
				_peerLeft = new RedRopePeer();
				addChild(_peerLeft);
			}
			
			if(!_peerRight)
			{
				_peerRight = new RedRopePeer();
				addChild(_peerRight);
			}
			
			var leftPos:Point    = startPos.x<endPos.x?startPos:endPos;
			var rightPos:Point   = startPos.x<endPos.x?endPos:startPos;
			
			var drawWidth:Number = Point.distance(leftPos, rightPos);
			_angle = Math.asin((rightPos.y-leftPos.y)/drawWidth);
			
			_mcRope.width = drawWidth;
			_mcRope.x     = -drawWidth/2;
			_mcRope.y     = -DRAW_HEIGHT/2;
			
			_peerLeft.x   = -drawWidth/2;
			_peerLeft.y   = _mcRope.y+_mcRope.height/2;
			
			_peerRight.x  = drawWidth/2;
			_peerRight.y   = _mcRope.y+_mcRope.height/2;
			/*
			graphics.beginFill(0xFF0000);
			graphics.drawRoundRect(-drawWidth/2, -DRAW_HEIGHT/2, drawWidth, DRAW_HEIGHT, 2);
			graphics.endFill();
			*/
			
			x = leftPos.x+drawWidth/2;
			y = (leftPos.y+rightPos.y+DRAW_HEIGHT)/2;
			rotation = _angle*180/Math.PI;
			
			_drawRectX = x;
			_drawRectY = y;
			_drawRectW = drawWidth;
			_drawRectH = DRAW_HEIGHT;
		}
	}
}